/*
 * @Author: liuying 247220246@qq.com
 * @Date: 2024-12-11 15:01:24
 * @LastEditors: liuying 247220246@qq.com
 * @LastEditTime: 2024-12-18 15:43:05
 * @FilePath: \vite-book-react\src\hooks\useRequest\axiosInstance.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
const axiosConfig:AxiosRequestConfig = {
  timeout: 5000,
  baseURL:"'http://106.14.223.52",
  headers: {
    "Content-Type": "application/json;charset=utf-8",
  },
  responseType: "json", 
};
const axiosInstance = axios.create(axiosConfig);
// axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {
//   return config;
// }, (error) => {
//   return Promise.reject(error);
  
// }
// );
// axiosInstance.interceptors.response.use((response: AxiosResponse) => {
//   return response;
  
// }, (error) => {
//   return Promise.reject(error);
  
// })
// export const GET = (url: any, config = {}) => axiosInstance.get(url, config);
axiosInstance.interceptors.request.use(
  (config: AxiosRequestConfig) => {
  return config;
  },
  (error: AxiosError) => {
    return Promise.reject(error);
  }
);
axiosInstance.interceptors.response.use(
  (res: AxiosResponse) => {
    console.log(res);
    
    if (res.status !== 200 || !res.data) {
      throw 'error';
    }
    return res.data;
  },
  (error: AxiosError) => {
    throw error;
  }
);
export default axiosInstance;